package com.maori.languageapp.discover.word;

import java.util.ArrayList;
import java.util.HashMap;

import com.maori.languageapp.R;
import com.maori.languageapp.adapter.Languageapp_Curate_AudioView_Activity;
import com.maori.languageapp.adapter.Languageapp_Curate_VideoView_Activity;
import com.maori.languageapp.consts.ImageLoader;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class Maori_Discover_Word_AudioList_Adapter extends BaseAdapter {
	// Declare Variables
	Context context;
	LayoutInflater inflater;
	ArrayList<HashMap<String, String>> data;
	//Button videoview_example;
	ImageLoader imageLoader;

	public Maori_Discover_Word_AudioList_Adapter(Context context,
			ArrayList<HashMap<String, String>> arraylist) {
		this.context = context;
		data = arraylist;
		imageLoader = new ImageLoader(context);

	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		// Declare Variables

		TextView first_name,last_name,Discover_example_likes;
		ImageView flag,userimage;
		Button setDefImageAction,setLikeImageAction,urlreader;
		
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View itemViewImages = inflater.inflate(R.layout.languageapp_discover_audio,
				parent, false);
		
		// Get the position from the results
		HashMap<String, String> resultp = new HashMap<String, String>();
		resultp = data.get(position);
		// Locate the ImageView in listview_item.xml
		first_name = (TextView) itemViewImages.findViewById(R.id.firstname);
		last_name = (TextView) itemViewImages.findViewById(R.id.lastname);
	/*	flag = (ImageView) itemViewImages.findViewById(R.id.ImageView_example);*/
		userimage = (ImageView) itemViewImages.findViewById(R.id.userimggriditem);
		
		Discover_example_likes = (Button) itemViewImages.findViewById(R.id.Discover_example_likes);
		setDefImageAction = (Button) itemViewImages.findViewById(R.id.setDefAction);
		setLikeImageAction = (Button) itemViewImages.findViewById(R.id.setLikeAction);
		urlreader  = (Button) itemViewImages.findViewById(R.id.urlreader);
		
		imageLoader.DisplayImage(resultp.get(Maori_Discover_Word_Details.IMAGEMID),userimage);
		first_name.setText(resultp.get(Maori_Discover_Word_Details.IMAGEfirst_name));
		last_name.setText(resultp.get(Maori_Discover_Word_Details.IMAGElast_name));
		Discover_example_likes.setText("Likes ("+resultp.get(Maori_Discover_Word_Details.IMAGETotalsLikes)+")");
		setLikeImageAction.setText(resultp.get(Maori_Discover_Word_Details.IMAGENID)+"/"+resultp.get(Maori_Discover_Word_Details.IMAGEUID));
		setDefImageAction.setText(resultp.get(Maori_Discover_Word_Details.IMAGENID)+"/"+resultp.get(Maori_Discover_Word_Details.IMAGEUID) + "/"+ resultp.get(Maori_Discover_Word_Details.IMAGENM_ID));
		
		// Capture button clicks on ListView items
		urlreader.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// Get the position from the results
				HashMap<String, String> resultp = new HashMap<String, String>();
				resultp = data.get(position);
				
				Log.e("REQUEST :", "URL *********** :" + resultp.get(Maori_Discover_Word_Details.IMAGEM_Source));
				Intent intent = new Intent(context,
						Languageapp_Curate_AudioView_Activity.class);
				intent.putExtra("SourceURL",resultp.get(Maori_Discover_Word_Details.IMAGEM_Source));
				context.startActivity(intent);
				
				/*Intent intent = new Intent(activity, LangiageApp_SoundPlayer_Fancy.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				Bundle bundle = new Bundle();
						
				bundle.putString("audio_title", MID_s[location]);  
				bundle.putString("audio_url", M_Source_s[location]);
				
				intent.putExtras(bundle);
				context.startActivity(intent);*/
			}
		});

		return itemViewImages;
	}
	
}